﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;

namespace PTTPOS_Solution.DAL
{
    public static class Materials_DA
    {
        public static DataTable ListMaterial = new DataTable();

        public static void GetListMaterial(string id)
        {
            MySqlCommand com = new MySqlCommand("select tblmaterials.id, amount, id_unit, name2, value from tblmaterials inner join tblunits on tblmaterials.id_unit = tblunits.id where tblmaterials.id = @id", Connection_PTTPOS.GetConnection());
            com.Connection.Open();
            com.Parameters.AddWithValue("@id", id);
            MySqlDataAdapter da = new MySqlDataAdapter(com);
            ListMaterial.Clear();
            da.Fill(ListMaterial);
            com.Connection.Close();
        }

        public static void UpdateMaterial(string id, decimal amount)
        {
            MySqlCommand com = new MySqlCommand("update tblmaterials set Amount = @amount where id=@id", Connection_PTTPOS.GetConnection());
            com.Parameters.AddWithValue("@id", id);
            com.Parameters.AddWithValue("@amount", amount);
            com.Connection.Open();
            com.ExecuteNonQuery();
            com.Connection.Close();
        }
    }
}
